home *** CD-ROM | disk | FTP | other *** search
- page 60,132
- TITLE CREATE - BASIC subrtn to decode track 40 for SMARTERM 100 ver. 4.0c
- ;----------------------------------------------------------------------
- ;
- ; This subroutine is called from BASIC using:
- ;
- ; CALL CREATE(FILE$,ERROR%)
- ;
- ; Passed: FILE$ = Name of file to create. An ASCIIZ string
- ; with Drive, path, filename, and ending with
- ; a byte of zero.
- ; Returned: ERROR%= Integer for the return of an error condition.
- ; The following values can be returned:
- ; 00 - No error
- ; 01 - Incorrect DOS version, must be higher than 2.00
- ; 02 - File not found
- ; 03 - Path not found
- ; 04 - Too many open files
- ; 05 - File access denied
- ; 06 - Invalid handle
- ; 07
- ; : - Error reading sector number 1-9
- ; 15
- ; 16 - Correct number of bytes not read or written
- ; to file
- ; 17 - Error resetting diskette system
- ;
- ; by Keith M. Bailey 12/29/84 version 0.01
- ;
- ;----------------------------------------------------------------------
- DATASG SEGMENT PARA 'DATA'
- BUFFER DB 0400H*9 DUP(?) ;Buffer to store 9 decodes sectors
- FILE DB 255 DUP(00) ;Space to store filename
- HANDLE DW 00 ;Store file handle
- DSKPRM DB 0BH DUP(00) ;Space for disk parameter table
- OFF_1E DW 00 ;Store address of old disk
- SEG_1E DW 00 ; parameter table
- TRIES DB 00 ;Number of tries at disk access
- DATASG ENDS
- ;----------------------------------------------------------------------
- PUBLIC CREATE, FMERGE
- CODESG SEGMENT PARA 'CODE'
- ASSUME CS:CODESG,DS:NOTHING,ES:DATASG
- CREATE PROC FAR
- PUSH BP ;Save BP
- MOV BP,SP
- PUSH ES ;Save ES
- MOV AX,DATASG
- MOV ES,AX ;Set ES = DATASG
-
- MOV AX,00 ;Initialize with no error
- CALL ERROR
-
- MOV AH,30H
- INT 21H ;Get DOS version
- CMP AL,02 ;Is it 2.00 or above
- JAE OK1 ; Yes - continue
- MOV AX,01 ; No - set error condition
- CALL ERROR ; and leave
- JMP DONE
-
- OK1: CALL GET_FILENAME
-
- PUSH DS
- MOV AX,DATASG
- MOV DS,AX ;Set DS = DATASG
- MOV DX,OFFSET FILE ;DS:DX points to ASCIIZ string filename
- MOV CX,00 ;Normal file attribute
- MOV AH,3CH
- INT 21H ;Create file
- JNC OK2 ;If no error continue
- POP DS ;Error - restore DS
- CALL ERROR ; set error condition
- JMP DONE ; and leave
-
- OK2: MOV HANDLE,AX ;Save file handle
- CALL NEW_PARMS ;Get new disk parameter table
- CALL RESET ;Reset diskette system
- MOV TRIES,00 ;Set number of tries to 0
- MOV DX,0000H ;Drive A, head 00
- MOV CX,2801H ;Track 40, sector 1
- MOV BX,OFFSET BUFFER ;Point to BUFFER
- MOV AX,0201H ;Read one sector
-
- NXT: INT 13H
- JNC SECT9 ;Error encountered ?
- CMP AH,10H ;Was it bad CRC ?
- JNE ERR1 ; No - something's wrong
- CMP CL,09 ;Is it sector 9 ?
- JE ERR1 ; Yes - something's wrong
- INC CL ;Next sector
- ADD BX,0400H ;Point along in BUFFER
- MOV AX,0201H ;Read one sector
- MOV TRIES,00 ;Set number of tries to 0
- JMP NXT ;Read next sector
-
- ERR1: INC TRIES ;Keep track of tries
- CMP TRIES,03 ;If more than 3 tries
- JA ERR2 ; exit with error message
- CALL RESET ;Reset diskette system
- MOV AX,0201 ;Read one sector
- JMP NXT ;Try it again
-
- ERR2: MOV AX,06 ;Base of error code
- MOV CH,00
- ADD AX,CX ;Add number of sector being read
- POP DS ;Restore DS
- CALL ERROR ;Set error code
- JMP DONE ;Exit
-
- SECT9: CMP CL,09 ;Was the 9th sector read
- JNE ERR1 ; No - try it again
-
- CALL RESTORE ;Restore original disk parameters
-
- MOV BX,HANDLE ;File handle
- MOV CX,0400H*9 ;Number of bytes to write
- MOV DX,OFFSET BUFFER ;DS:DX points to BUFFER
- MOV AH,40H
- INT 21H ;Write to file
- JNC OK3 ;Jump if no error
- POP DS ;Restore DS
- CALL ERROR ;Set error code
- JMP DONE ;Exit
-
- OK3: CMP AX,0400H*9 ;All bytes written ?
- JE OK4 ; Yes - continue
- POP DS ;Restore DS
- MOV AX,16
- CALL ERROR ;Set error code
- JMP DONE ;Exit
-
- OK4: MOV BX,HANDLE
- MOV AH,3EH
- INT 21H ;Close file handle
- POP DS ;Restore DS
- JNC DONE ;If no error - DONE
- CALL ERROR ;Set error code
-
-
- DONE: POP ES ;Restore ES
- POP BP ;Restore BP
- RET 4 ;Return
-
- CREATE ENDP
-
- ;----------------------------------------------------------------------
- ;
- ; Subroutine to store error condition in ERROR%.
- ;
- ; Passed: AX = error condition.
- ; DS = must point to BASIC's data segment
- ;
- ; Registers destroyed: none
- ;----------------------------------------------------------------------
- ERROR PROC NEAR
- PUSH SI
- MOV SI,6[BP] ;Point to ERROR%
- MOV WORD PTR DS:[SI],AX ;Move error code into ERROR%
- POP SI ;Restore SI
- CALL RESTORE ;Restore original disk parameters
- RET ;Return
- ERROR ENDP
-
- ;----------------------------------------------------------------------
- ;
- ; Subroutine to store filename (1st parameter), in FILE.
- ;
- ; Passed: AX = error condition.
- ; DS = must point to BASIC's data segment
- ;
- ; Registers destroyed: CX,DI,SI
- ;----------------------------------------------------------------------
- GET_FILENAME PROC NEAR
- MOV DI,8[BP] ;Point to string descriptor
- MOV CL,BYTE PTR DS:[DI] ;String length into CL
- MOV CH,00
- MOV SI,WORD PTR DS:[DI+2] ;String offset into SI
- MOV DI,OFFSET FILE ;ES:DI points to FILE
- CLD
- REPNZ MOVSB ;Store filename in FILE
- RET ;Return
- GET_FILENAME ENDP
-
- ;----------------------------------------------------------------------
- ;
- ; Subroutine to set up new disk parameter table.
- ;
- ; Passed: none
- ;
- ; Registers destroyed: none
- ;----------------------------------------------------------------------
- NEW_PARMS PROC NEAR
- PUSH DS ;Save registers and segments
- PUSH SI
- PUSH DI
- PUSH CX
- PUSH AX
- MOV AX,00
- MOV DS,AX ;Set DS = 00
- CLI ;Disable interrupts
- LDS SI,DS:[1EH*4] ;Point to disk parameters
- MOV OFF_1E,SI ;Save address of old disk parameters
- MOV SEG_1E,DS
- MOV DI,OFFSET DSKPRM ;Place to store parameters
- MOV CX,0BH ;Number of bytes in parameter table
- CLD
- REPNZ MOVSB ;Move them
- MOV AX,00
- MOV DS,AX ;Set DS = 00
- MOV DI,OFFSET DSKPRM
- MOV WORD PTR DS:[1EH*4],DI ;Point INT 1EH to DSKPRM
- MOV WORD PTR DS:[1EH*4+2],ES
- MOV BYTE PTR ES:[DI+3],03 ;Set disk parameters for 1024
- ; bytes per sector
- STI ;Enable interrupts
- POP AX
- POP CX
- POP DI
- POP SI
- POP DS ;Restore registers and segments
- RET ;Return
- NEW_PARMS ENDP
-
- ;----------------------------------------------------------------------
- ;
- ; Subroutine to reset the diskette system.
- ; If error is detected, ERROR% is set and the program is exited
- ;
- ; Passed: none
- ;
- ; Registers destroyed: none
- ;----------------------------------------------------------------------
- RESET PROC NEAR
- PUSH DX ;Save registers
- PUSH CX
- PUSH BX
- PUSH AX
- MOV CX,00 ;Count tries
-
- AGAIN: INC CX
- CMP CX,03 ;If more than three tries - quit
- JA ERR10
- MOV AX,00
- INT 13H ;Reset diskette system
- CMP AH,00 ;Was there an error ?
- JNE AGAIN ; Yes - retry
-
- POP AX ;Restore registers
- POP BX
- POP CX
- POP DX
- RET ;Return
-
- ERR10: POP AX ;Clear stack
- POP BX
- POP CX
- POP DX
- MOV AX,17 ;Error code = 17
- POP BX ;Original return offset into BX
- POP DS ;Restore DS
- CALL ERROR ;Set error condition
- JMP DONE ;Exit
- RESET ENDP
-
- ;----------------------------------------------------------------------
- ;
- ; Subroutine restore the original disk parameters.
- ;
- ; Passed: none
- ;
- ; Registers destroyed: none
- ;----------------------------------------------------------------------
- RESTORE PROC NEAR
- CMP OFF_1E,00 ;Is offset = 00
- JNE OK21 ; No - needs to be switched
- CMP SEG_1E,00 ;Is segment = 00
- JE DONE2 ; Yes - don't switch
-
- OK21: PUSH DS
- PUSH AX
- MOV AX,00
- MOV DS,AX ;Set DS to 0000
- CLI ;Disable interrupts while
- ; changing interrupt vectors
- MOV AX,OFF_1E ;Move offset for original INT 1EH
- MOV DS:[1EH*4],AX ; into interrupt table
- MOV AX,SEG_1E ;Move segment for original INT 1EH
- MOV DS:[1EH*4+2],AX ; into interrupt table
- STI ;Enable interrupts
- POP AX
- POP DS
-
- DONE2: RET
- RESTORE ENDP
-
- ;----------------------------------------------------------------------
- ;
- ; This subroutine is called from BASIC using:
- ;
- ; CALL FMERGE(FILE$,ERROR%)
- ;
- ; Passed: FILE$ = Name of file to merge decoded sectors with.
- ; An ASCIIZ string with Drive, path, filename,
- ; and ending with a byte of zero.
- ; Returned: ERROR%= Integer for the return of an error condition.
- ; Error codes are the same as described in the
- ; subroutine create.
- ;
- ; by Keith M. Bailey 12/29/84 version 0.01
- ;
- ;----------------------------------------------------------------------
- ASSUME CS:CODESG,DS:NOTHING,ES:DATASG
- FMERGE PROC FAR
- PUSH BP ;Save BP
- MOV BP,SP
- PUSH ES ;Save ES
- MOV AX,DATASG
- MOV ES,AX ;Set ES = DATASG
-
- MOV AX,00 ;Initialize with no error
- CALL ERROR
-
- CALL GET_FILENAME ;Filename in FILE
-
- PUSH DS ;Save DS
- MOV AX,DATASG
- MOV DS,AX ;Set DS = DATASG
- MOV DX,OFFSET FILE ;DS:DX points to filename
- MOV AX,3D02H ;Open file for both reading
- INT 21H ; and writing
- JNC OK30 ;If no error - continue
- POP DS ;Restore DS
- CALL ERROR ;Set error code
- JMP DONE3 ;Exit
-
- OK30: MOV HANDLE,AX ;Save file handle
- MOV BX,AX ;File handle into BX
-
- OK32: MOV AL,00 ;Move pointer to an offset
- MOV CX,00
- MOV DX,0010H ;Pointer = 0000:0010
- MOV AH,42H
- INT 21H ;Advance file read/write pointer
- JNC OK33 ;If no error - continue
- POP DS ;Restore DS
- CALL ERROR ;Set error code
- JMP DONE3 ;Exit
-
- OK33: MOV CX,0400H*9 ;Number of bytes to write
- MOV DX,OFFSET BUFFER ;DS:DX points to data to write
- MOV AH,40H
- INT 21H ;Write to file
- JNC OK34 ;If no error - continue
- POP DS ;Restore DS
- CALL ERROR ;Set error code
- JMP DONE3 ;Exit
-
- OK34: CMP AX,0400H*9 ;Correct number of bytes written ?
- JE OK35 ; Yes - continue
- POP DS ;Restore DS
- MOV AX,16
- CALL ERROR ;Set error code
- JMP DONE3 ;Exit
-
- OK35: MOV AH,3EH
- INT 21H ;Close file
- POP DS
- JNC DONE3 ;If no error - leave
- CALL ERROR ;Set error code
-
- DONE3: POP ES ;Restore ES and BP
- POP BP
- RET 4 ;Return
-
- FMERGE ENDP
-
- CODESG ENDS
- END
-